{layout name="layout" /}

<nav class="breadcrumb">
	<i class="Hui-iconfont">&#xe67f;</i>
	<a href="{:url('index/index')}"> 首页</a>
	<span class="c-gray en">&gt;</span>
	<a href="{:url('sys_role/index')}">角色管理</a>
	<span class="c-gray en">&gt;</span>
	<a href="javascprit:;">{$data.id ? '修改' : '新增'}</a>
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
		href="javascript:location.replace(location.href);" title="刷新">
		<i class="Hui-iconfont">&#xe68f;</i>
	</a>
</nav>

<div class="Hui-article">
	<article class="cl pd-20">
		<form action="{:url('sys_role/save?id='.$data.id)}" method="post" class="form form-horizontal" id="form-admin-role-add">
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>角色名称：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="{$data.name}" placeholder="" id="name" name="name"
					datatype="*4-16" nullmsg="角色名称">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-2">备注：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="{$data.note}" placeholder="备注" id="note" name="note">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-2">权限选择：</label>
				<div class="formControls col-xs-8 col-sm-9">
					{foreach $dataPermission as $value}
					<dl class="permission-list">
						<dt>
							<label>
								<input type="checkbox" value="{$value.id}" id="check_{$value.id}"  name="perm_check[]" {if condition="in_array($value.id, $rolePowers)"}checked{/if}>
							{$value.name}</label>
						</dt>
						{notempty name='value.child'}
							{foreach $value.child as $val}
						<dd>
							<dl class="cl permission-list2">
								<dt>
									<label class="">
										<input type="checkbox" value="{$val.id}" name="perm_check[]" id="check_{$val.id}"{if condition="in_array($val.id, $rolePowers)"}checked{/if}>
										{$val.name}</label>
								</dt>
								{notempty name='val.child'}
								<dd>
									{foreach $val.child as $vo}
									<label class="">
										<input type="checkbox" value="{$vo.id}" name="perm_check[]" id="check_{$val.id}" {if condition="in_array($vo.id, $rolePowers)"}checked{/if}>
										{$vo.name}</label>
									{/foreach}
								</dd>
								{/notempty}
							</dl>
						</dd>
						{/foreach}
						{/notempty}
					</dl>
					{/foreach}
				</div>
			</div>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<button type="submit" class="btn btn-success radius" id="admin-role-save"><i
							class="icon-ok"></i> 确定</button>
					<button type="button" class="btn btn-default radius" onClick="window.history.back();"><i
						class="Hui-iconfont">&#xe66b;</i>取消</button>
				</div>
			</div>
		</form>
	</article>
</div>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
	$(function () {
		$(".permission-list dt input:checkbox").click(function(){
			$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
		});
		$(".permission-list2 dd input:checkbox").click(function(){
			var l =$(this).parent().parent().find("input:checked").length;
			var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
			if($(this).prop("checked")){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
			}
			else{
				if(l==0){
					$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
				}
				if(l2==0){
					$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
				}
			}
		});
	})
</script>
<!--请在上方写此页面业务相关的脚本-->